package marker.micro.login.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;

import marker.micro.login.entity.User;

public final class SecurityUserFactory {

    private SecurityUserFactory() {
    }

    public static SecurityUser create(User user) {
	return new SecurityUser(
		user.getId(),
		user.getUsername(),
		user.getPassword(),
		mapToGrantedAuthorities("ROLE_USER"),
		user.getEnabled()
		);
    }

    private static List<GrantedAuthority> mapToGrantedAuthorities(String authority) {
	List<GrantedAuthority> grantedauthorities = new ArrayList<GrantedAuthority>();
	SimpleGrantedAuthority simplegrantedauthority = new SimpleGrantedAuthority(authority);
	grantedauthorities.add(simplegrantedauthority);
	return grantedauthorities;
    }

}
